﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp.TestFunc.代码备份
{
    public class Example_Delegate
    {

        public class Student
        {

            public string Name { get; set; }
            public Student() { }

            public void DisplayName()
            {
                Console.WriteLine(this.Name);
            }

        }

        public class MyClass
        {
            public static int sf;
            static MyClass()
            {
                sf = 10;
            }
        }

        public class TimePeriod
        {
            private double seconds;
            public double Hours
            {
                get
                {
                    return seconds / 3600;
                }
                set
                {
                    seconds = value * 3600;
                }
            }
        }

        public class Tpoint
        {
            int x, y;
            public int px
            {
                get { return x; }
                set { x = value; }
            }
            public int py
            {
                get { return y; }
                set { y = value; }
            }
        }


        //修饰符 delegate 返回类型 方法名(参数);
        public delegate void MyDelegate(int n);

        public static void printNum(int num)
        {
            Console.WriteLine(num);
        }

        public static void Run()
        {
            //实例化委托对象：5种方式一样的
            MyDelegate myDelegate = new MyDelegate(printNum);

            MyDelegate myDelegate1 = printNum;

            //委托与匿名方法
            MyDelegate myDelegate2 = delegate (int num)
            {
                Console.WriteLine(num);
            };

            //委托与lamda表达式
            MyDelegate myDelegate3 = num =>
            {
                Console.WriteLine(num);
            };

            MyDelegate myDelegate4 = num => Console.WriteLine(num);

            myDelegate(2);
            myDelegate1(2);
            myDelegate2(2);
            myDelegate3(2);
            myDelegate4(2);
            Console.ReadKey();
        }
    }
}
